package com.woniuxy.provider;

import com.woniuxy.entity.DishCategory;
import com.woniuxy.entity.Specs;
import org.apache.ibatis.jdbc.SQL;

public class SpecsProvider {

        public String update(Specs specs) {
            return new SQL() {
                {
                    /*双大括号初始化*/
                    UPDATE("gfr_specs");
                    if (specs.getName() != null && specs.getName().length()!= 0) {
                        SET("name='" + specs.getName() + "'");
                    }
                    if (specs.getValue() != null && specs.getValue().length()!= 0) {
                        SET("value='" + specs.getValue() + "'");
                    }
                    if (specs.getStatus() != null && specs.getStatus().length() != 0) {
                        SET("status='" + specs.getStatus() + "'");
                    }
                    if ( specs.getSort() != 0) {
                        SET("sort='" + specs.getSort() + "'");
                    }
                    WHERE("id=" + specs.getId());
                }
            }.toString();
        }

    public String getByCondition(Specs specs) {
        return new SQL() {{
            SELECT("*");
            FROM("gfr_specs");
            if (specs != null) {
                if (specs.getName() != null && specs.getName().length() != 0) {
                    WHERE("name ='" +specs.getName() + "'");
                }
                if (specs.getValue() != null && specs.getValue().length() != 0) {
                    WHERE("value ='" + specs.getValue() + "'");
                }
                if (specs.getStatus() != null && specs.getStatus().length() != 0) {
                    WHERE("status ='" + specs.getStatus() + "'");
                }
                if (specs.getSort() != 0) {
                    WHERE("sort ='" + specs.getSort() + "'");
                }

            }
        }}.toString();
    }


}
